package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.main.entity.UserInfoBean;
import com.bana.fvs.app.module.info.entity.LogOutBean;
import com.bana.fvs.app.mvp.contract.UserInfoContract;
import com.bana.fvs.app.mvp.model.UserInfoModel;
import com.bana.fvs.app.util.UserInfoUtils;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;

/**
 * Created by ${wei} on 2017/4/14.
 */

public class UserInfoPresenter extends UserInfoContract.AbsuserInfoPresenter {
    @Override
    public void http_logout(Activity activity) {
        mModel.http_logout(UserInfoUtils.getInstance().getToken(activity))
                .callback(new MyDefaultCallback<LogOutBean>(activity, true) {
                    @Override
                    public void onError(CommException e) {
                        if (getView() != null) {
                            getView().onError(e);
                        }
                    }

                    @Override
                    public void response(LogOutBean outBean) {
                        if (getView() != null) {
                            getView().onResponse(outBean);
                        }
                    }
                });
    }

    @Override
    public void http_updatePhone(Activity activity, final String phone) {
        mModel.http_updatePhone(UserInfoUtils.getInstance().getToken(activity), phone,
                new MyDefaultCallback<String>(activity, true) {
                    @Override
                    public void onError(CommException e) {
                        if (getView() != null) {
                            getView().onError(e);
                        }
                    }

                    @Override
                    public void response(String s) {
                        if (getView() != null) {
                            getView().onUpdatePhoneSuccess(phone);
                        }
                    }
                });
    }

    @Override
    public void getUserInfo(Activity activity) {
        mModel.http_getUserInfo(UserInfoUtils.getInstance().getToken(activity))
                .callback(new MyDefaultCallback<UserInfoBean>(activity, true) {
                    @Override
                    public void onError(CommException e) {
                        if (getView() != null) {
                            getView().onError(e);
                        }
                    }

                    @Override
                    public void response(UserInfoBean userInfoBean) {
                        if (getView() != null) {
                            getView().onUserInfoSuccess(userInfoBean);
                        }
                    }
                });
    }

    @Override
    protected UserInfoContract.AbsUserInfoModel createModel() {
        return new UserInfoModel();
    }
}
